﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Diagnostics;

namespace TST.DemoCode.Domain
{
    public class Themes
    {
        private List<Theme> _themes;

        public Themes()
        {
            _themes = new List<Theme>();
        }

        public List<Theme> ThemeList
        {
            get
            {
                return _themes;
            }
        }

        public Boolean GetFromXml(XElement xmlNode)
        {
            Trace.WriteLine("Read themes from XML.");
            if (xmlNode == null)
            {
                Trace.WriteLine("No themes found.");
                return false;
            }

            XNamespace nmsp = XNamespace.Get(Theme.XmlNameSpaceThemes);
            var themes = from t in xmlNode.Elements(nmsp + "Theme")
                         select new Theme
                         {
                             TemplateID = t.Element(nmsp + "TemplateID").Value,
                             DisplayName = t.Element(nmsp + "DisplayName").Value,
                             Description = t.Element(nmsp + "Description").Value,
                             Thumbnail = t.Element(nmsp + "Thumbnail").Value,
                             Preview = t.Element(nmsp + "Preview").Value,
                             LCID = t.Element(nmsp + "LCID").Value
                         };
            _themes = themes.ToList();
            return true;
        }
    }
}

